<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>判断UA</title>
</head>
<body>
    <script>
var UA = window.navigator.userAgent;
var ua = UA.toLowerCase();
var browserRegExp = {
    ie:/msie\s*(\d+(?:\.\d+)?)+/,
    chrome:/chrome\/(\d+(?:\.\d+)?)+/,
    firefox:/firefox\/(\d+(?:\.\d+)?)+/,
    safari:/version\/(\d+(?:\.\d+)?)\s*safari/,
    opera:/opera[ |\/](\d+(?:\.\d+)?)/
};
$ = {};
$.browser = 'unknow';
$.browserVersion = 0;

function checkUA(ua,browser,version){
    ua = ua.toLowerCase();
    for(var i in browserRegExp){
        var match = browserRegExp[i].exec(ua);
        if(match){
            $.browser = i;
            if(browser===i && version==match[1]){
            }else{
                console.log(browser+'|'+version+'|'+match[1]+':'+ua);
            }

            break;
        }else{
            // console.log(ua);
        }
    }
}
var arr = [
    ['chrome',19.0,'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1061.1 Safari/536.3'],
    ['chrome',24.0,'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.14 (KHTML, like Gecko) Chrome/24.0.1292.0 Safari/537.14'],
    ['chrome',15.0,'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.861.0 Safari/535.2'],
    ['chrome',4.0,'Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/4.0.211.2 Safari/532.0'],
    ['chrome',0.2,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13(KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13'],


    ['safari',6.0,'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25'],
    ['safari',5.0,'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; da-dk) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1'],
    ['safari',5.1,'Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko ) Version/5.1 Mobile/9B176 Safari/7534.48.3'],
    ['safari',5.0,'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; th-th) AppleWebKit/533.17.8 (KHTML, like Gecko) Version/5.0.1 Safari/533.17.8'],
    ['safari',4.0,'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_4; en-gb) AppleWebKit/528.4+ (KHTML, like Gecko) Version/4.0dp1 Safari/526.11.2'],
    ['safari',4.0,'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7'],
    ['safari',4.0,'Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10gin_lib.cc'],
    ['safari',4.0,'Mozilla/5.0 (Windows; U; Windows NT 5.1; fi-FI) AppleWebKit/528.16 (KHTML, like Gecko) Version/4.0 Safari/528.16'],
    ['safari',3.2,'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; de-de) AppleWebKit/525.28.3 (KHTML, like Gecko) Version/3.2.3 Safari/525.28.3'],
    ['safari',3.2,'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; fr-fr) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1'],
    ['safari',3.0,'Mozilla/5.0 (Windows; U; Windows NT 6.0; en) AppleWebKit/525+ (KHTML, like Gecko) Version/3.0.4 Safari/523.11'],
    ['safari',2.0,'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418 (KHTML, like Gecko) Safari/417.9.2'],
    ['safari',1.3,'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; de-de) AppleWebKit/312.8 (KHTML, like Gecko) Safari/312.5_Adobe'],
    ['safari',1.0,'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; de-de) AppleWebKit/85.7 (KHTML, like Gecko) Safari/85.5'],
    ['firefox',23.0,'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20130406 Firefox/23.0'],
    ['firefox',16.0,'Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1'],
    ['firefox',6.0,'Mozilla/5.0 (Windows NT 5.0; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0'],
    ['firefox',6.0,'Mozilla/5.0 (Windows NT 5.1; rv:6.0) Gecko/20100101 Firefox/6.0 FirePHP/0.6'],
    ['firefox',5.0,'Mozilla/5.0 (X11; Linux i686 on x86_64; rv:5.0a2) Gecko/20110524 Firefox/5.0a2'],
    ['firefox',4.0,'Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)'],
    ['firefox',4.0,'Mozilla/5.0 (Windows NT 6.1; rv:1.9) Gecko/20100101 Firefox/4.0'],
    ['firefox',3.5,'Mozilla/5.0 (Windows; U; Windows NT 6.0; de; rv:1.9.1.9) Gecko/20100315 Firefox/3.5.9 GTB7.0 (.NET CLR 3.0.30618)'],
    ['firefox',2.1,'Mozilla/5.0 (Windows; U; Windows NT 6.0; de; rv:1.9.0.15) Gecko/2009101601 Firefox 2.1 (.NET CLR 3.5.30729)'],
    ['firefox',2.0,'Mozilla/5.0 (X11; U; SunOS sun4v; en-US; rv:1.8.1.3) Gecko/20070321 Firefox/2.0.0.3'],
    ['firefox',1.6,'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9a1) Gecko/20060112 Firefox/1.6a1'],
    ['firefox',1.0,'Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.7.6) Gecko/20050317 Firefox/1.0.2 (ax)'],
    ['firefox',0.1,'Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; rv:1.7.3) Gecko/20040913 Firefox/0.10'],
    ['ie',10.6,'Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0'],
    ['ie',10.0,'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)'],
    ['ie',9.0,'Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US))'],
    ['ie',9.0,'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Zune 4.0; InfoPath.3; MS-RTC LM 8; .NET4.0C; .NET4.0E)'],
    ['ie',8.0,'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MS-RTC LM 8; InfoPath.3; .NET4.0C; .NET4.0E) chromeframe/8.0.552.224'],
    ['ie',7.0,'Mozilla/4.0(compatible; MSIE 7.0b; Windows NT 6.0)'],
    ['ie',7.0,'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)'],
    ['ie',6.0,'Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)'],
    ['ie',6.1,'Mozilla/4.0 (compatible; MSIE 6.1; Windows XP; .NET CLR 1.1.4322; .NET CLR 2.0.50727)'],
    ['opera',12.14,'Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14'],
    ['opera',12.02,'Opera/12.80 (Windows NT 5.1; U; en) Presto/2.10.289 Version/12.02'],
    ['opera',12.0,'Mozilla/5.0 (Windows NT 5.1) Gecko/20100101 Firefox/14.0 Opera/12.0'],
    ['opera',12.00,'Opera/12.0(Windows NT 5.1;U;en)Presto/22.9.168 Version/12.00'],
    ['opera',11.62,'Opera/9.80 (Windows NT 6.0; U; pl) Presto/2.10.229 Version/11.62'],
    ['opera',11.50,'Opera/9.80 (X11; Linux x86_64; U; fr) Presto/2.9.168 Version/11.50'],
    ['opera',11.11,'Mozilla/5.0 (Windows NT 5.1; U; en; rv:1.8.1) Gecko/20061208 Firefox/5.0 Opera 11.11'],
    ['opera',11.11,'Opera/9.80 (X11; Linux i686; U; es-ES) Presto/2.8.131 Version/11.11'],
    ['opera',11.10,'Opera/9.80 (Windows NT 6.1; U; zh-tw) Presto/2.7.62 Version/11.01'],
    ['opera',11.00,'Opera/9.80 (X11; Linux x86_64; U; pl) Presto/2.7.62 Version/11.00'],
    ['opera',11.00,'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; en) Opera 11.00'],
    ['opera',10.70,'Opera/9.80 (Windows NT 6.1; U; pl) Presto/2.6.31 Version/10.70'],
    ['opera',10.70,'Mozilla/5.0 (Windows NT 5.1; U; zh-cn; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6 Opera 10.70'],
    ['opera',10.63,'Opera/9.80 (Windows NT 5.2; U; zh-cn) Presto/2.6.30 Version/10.63'],
    ['opera',9.80,'Opera/9.80 (J2ME/MIDP; Opera Mini/5.0 (Windows; U; Windows NT 5.1; en) AppleWebKit/886; U; en) Presto/2.4.15'],
];

for(var i=0,len = arr.length;i<len;i++){
    checkUA(arr[i][2],arr[i][0],arr[i][1]);
}
</script>
</body>
</html>